package cn.tedu.api;

import java.math.BigDecimal;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        method();
        method2();
    }
    public static void method(){
        double a=new Scanner(System.in).nextDouble();
        double b=new Scanner(System.in).nextDouble();
        /*System.out.println(a+b);
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/b);*/
        BigDecimal c=new BigDecimal(a);
        BigDecimal d=new BigDecimal(b);
        System.out.println(c.add(d));
        System.out.println(c.subtract(d));
        System.out.println(c.multiply(d));
        System.out.println(c.divide(d));
    }
    public static  void method2(){
        double a=new Scanner(System.in).nextDouble();
        double b=new Scanner(System.in).nextDouble();
        BigDecimal bd1=new BigDecimal(Double.toString(a));
        BigDecimal bd2=new BigDecimal(a+"");
        BigDecimal bd0=new BigDecimal(String.valueOf(b));
        BigDecimal bd3 = bd1.add(bd2);//--加法
        System.out.println(bd3);

        bd3 = bd1.subtract(bd2) ;//--减法
        System.out.println(bd3);

        bd3 = bd1.multiply(bd2) ;//--乘法
        System.out.println(bd3);

        //除不尽时,会抛出异常:ArithmeticException
        //        bd3 = bd1.divide(bd2) ;//--除法
        //第一个参数是想和谁做运算...第二个参数是保留的位数...第三个参数是舍入模式
        bd3 = bd1.divide(bd2,5,BigDecimal.ROUND_HALF_UP) ;//--除法
        System.out.println(bd3);
    }

}


